from typing import Optional, List

from langchain_core.runnables import RunnableConfig
from pydantic import BaseModel

from .base import BaseNodes, tool_node
from ...models.graph import GraphState


class AskUserQuestionSchema(BaseModel):
    question: str


class AskUserSelectSchema(BaseModel):
    options: List[str]
    question: str
    multiple: Optional[bool] = False


class AskUserNodes(BaseNodes):

    @tool_node(args_schema=AskUserQuestionSchema)
    def ask_user_question(self, state: GraphState, *, config: Optional[RunnableConfig] = None):
        """
        向用户提问获取任务所需信息。用于解决歧义、澄清需求或收集详细信息。
        参数:
        - question: (必填) 需要询问的具体问题
        用法:
        <ask_user_question>
        <question>Your question here</question>
        </ask_user_question>
        """
        return self.wait_human_feedback()

    @tool_node(args_schema=AskUserSelectSchema)
    def ask_user_select(self, state: GraphState, *, config: Optional[RunnableConfig] = None):
        """
        向用户提供选择列表。用于从预定义选项中获取用户决策，支持单选或多选。
        参数:
        - options: (必填) 选项列表，每行一个选项
        - question: (必填) 询问问题或提示
        - multiple: (可选) 是否允许多选，默认false
        用法:
        <ask_user_select>
        <options>
        Option 1
        Option 2
        Option 3
        </options>
        <question>Your question here</question>
        <multiple>true or false (optional, defaults to false)</multiple>
        </ask_user_select>
        """
        return self.wait_human_feedback()
